package lab03.test01;

import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;

public class Test01 {
    public static void main(String[] args) {
        /**
         * 读文件基本操作：都一个文件并打印文件内容。
         *
         */
        String path = "D:\\hello.txt";

        //1.字符流来读

        //1.1 一次读一行字符
        BufferedReader reader = null;

        try {

            reader = new BufferedReader(new FileReader(path));
            String line = "";
            reader.read();

            //用while循环读文件
            while ((line = reader.readLine()) != null) {
                System.out.println(line);
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                //执行完后，关闭程序

                reader.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
}
